<?php
/**
 * Mall user management
 * @author Ice <iceinto@mallog.com.cn>
 */
class MemberAction extends CommonAction {
	public $gid = 4;
	public function _initialize() {
		$this->assign ('nav', 5);
		parent::_initialize();
	}

	/**
	 * Update my passwd
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function passwd(){
		$id = $this->getLoginUserInfo();
		if($id){
			if(isPost()){
				$user = M('User')->find($id);
				if($user['passwd'] != md5(getPost('oldPasswd'))){
					$this->errorLang('_OLD_PASSWD_ERROR');
				}
				//判断老密码是否正确
				$passwd = hh(getPost('passwd'));
				$repasswd = hh(getPost('repasswd'));
				if($passwd && $repasswd){
					if($passwd == $repasswd){
						$data = array();
						$data['passwd'] = md5($passwd);
						$data['id'] = $user['id'];
						if(M('User')->save($data)){
							$this->successLang('_UPDATE_SUCCESS');
						}else{
							$this->errorLang('_PASSWD_UPDATE_LOSE');
						}
					}else{
						$this->errorLang('_PASSWD_AND_REPASSWD_MUST_EQUAL');
					}
				}else{
					$this->errorLang('_PASSWD_AND_REPASSWD_NO_EMPTY');
				}
			}
		}else{
			$this->errorLang('_USER_ID_ERROR');
		}
		$this->display();
	}

	/**
	 * 第三方账号绑定
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function oauth(){
		$url = SITE_URL.U('OAuth/weibo');
		$uid = $this->getLoginUserInfo();
		$OAuthModel = D('OAuth');
		$oauth = $OAuthModel->getOauth($uid);
		if(!$oauth['weibo']){
			vendor('WeiBo.WeiBo');
			$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
			$code_url = $o->getAuthorizeURL($url);
			$this->assign('weibo_login_url', $code_url);
		}
		$this->assign('oauth', $oauth);
		$this->display();
	}
}
?>